package com.example.mtblog.common;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
* @description: 返回请求统一处理
* @author MT
* @date 2023/10/11 21:56
* @version 1.0
*/


public class Result<T>{

    private Integer code;
    private String message;


    private String type;

    private T data;

    public Result(Integer code, String message, String type){
        this.code=code;
        this.message=message;
        this.type = type;
    }
    public Result(){

    }

    public Result(T data){this.data=data;}

    public static Result<?> success(){
        return  new Result<>(200, "成功","success");
    }
    public static <T> Result<T> success(T data){
        Result<T> result = new Result<T>(data);
        result.setCode(200);
        result.setType("success");
        result.setMessage("成功");
        return result;
    }
    public static <T> Result<T> success(T data , String message){
        Result<T> result = new Result<T>(data);
        result.setCode(200);
        result.setType("success");
        result.setMessage(message);
        return result;
    }


    public static Result<?> noAuth(String message){
        Result<?> result=new Result<>();
        result.setCode(403);
        result.setType("error");
        result.setMessage(message);
        return result;
    }


    public static Result<?> error(String message){
        Result<?> result=new Result<>();
        result.setCode(1);
        result.setType("error");
        result.setMessage(message);
        return result;
    }

    public static Result<?> error(Integer code ,String message ){
        Result<?> result=new Result<>();
        result.setCode(code);
        result.setType("error");
        result.setMessage(message);
        return result;
    }

    public static Result<?> warning(String message){
        Result<?> result=new Result<>();
        result.setCode(200);
        result.setType("warning");
        result.setMessage(message);
        return result;
    }





    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }


    public String getType() {
        return type;
    }

    public void setType(String type) {
        this.type = type;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message){
        this.message=message;
    }


    public T getData() {return data;}

    public void setData(T data) {this.data = data;}
}
